home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Text / Show / Less / less-252 / less.h < prev    next >
C/C++ Source or Header  |  1994-10-15  |  5KB  |  200 lines

  1. /*
  2.  * Copyright (c) 1984,1985,1989,1994  Mark Nudelman
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice in the documentation and/or other materials provided with 
  12.  *    the distribution.
  13.  *
  14.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
  15.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  17.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
  18.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  19.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
  20.  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
  21.  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
  22.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
  23.  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
  24.  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  */
  26.  
  27.  
  28. /*
  29.  * Standard include file for "less".
  30.  */
  31.  
  32. /*
  33.  * Include the file of compile-time options.
  34.  * The <> make cc search for it in -I., not srcdir.
  35.  */
  36. #include <defines.h>
  37.  
  38. /*
  39.  * Language details.
  40.  */
  41. #if HAVE_VOID
  42. #define    VOID_POINTER    void *
  43. #else
  44. #define    VOID_POINTER    char *
  45. #define    void  int
  46. #endif
  47.  
  48. #define    public        /* PUBLIC FUNCTION */
  49.  
  50. /* Library function declarations */
  51.  
  52. #if HAVE_SYS_TYPES_H
  53. #include <sys/types.h>
  54. #endif
  55. #if HAVE_STDIO_H
  56. #include <stdio.h>
  57. #endif
  58. #if HAVE_UNISTD_H
  59. #include <unistd.h>
  60. #endif
  61. #if HAVE_CTYPE_H
  62. #include <ctype.h>
  63. #endif
  64. #if STDC_HEADERS
  65. #include <stdlib.h>
  66. #include <string.h>
  67. #endif
  68.  
  69. #if !STDC_HEADERS
  70. char *getenv();
  71. off_t lseek();
  72. VOID_POINTER calloc();
  73. void free();
  74. #endif
  75.  
  76. #if !HAVE_UPPER_LOWER
  77. #define    isupper(c)    ((c) >= 'A' && (c) <= 'Z')
  78. #define    islower(c)    ((c) >= 'a' && (c) <= 'z')
  79. #define    toupper(c)    ((c) - 'a' + 'A')
  80. #define    tolower(c)    ((c) - 'A' + 'a')
  81. #endif
  82.  
  83. #ifndef NULL
  84. #define    NULL    0
  85. #endif
  86.  
  87. #ifndef HAVE_MEMCPY
  88. #ifndef memcpy
  89. #define    memcpy(to,from,len)    bcopy((from),(to),(len))
  90. #endif
  91. #endif
  92.  
  93. #define    BAD_LSEEK    ((off_t)-1)
  94.  
  95. /*
  96.  * Special types and constants.
  97.  */
  98. typedef long        POSITION;
  99. /*
  100.  * {{ Warning: if POSITION is changed to other than "long",
  101.  *    you may have to change some of the printfs which use "%ld"
  102.  *    to print a variable of type POSITION. }}
  103.  */
  104.  
  105. #define    NULL_POSITION    ((POSITION)(-1))
  106.  
  107. /*
  108.  * An IFILE represents an input file.
  109.  */
  110. #define    IFILE        VOID_POINTER
  111. #define    NULL_IFILE    ((IFILE)NULL)
  112.  
  113. /*
  114.  * The structure used to represent a "screen position".
  115.  * This consists of a file position, and a screen line number.
  116.  * The meaning is that the line starting at the given file
  117.  * position is displayed on the ln-th line of the screen.
  118.  * (Screen lines before ln are empty.)
  119.  */
  120. struct scrpos
  121. {
  122.     POSITION pos;
  123.     int ln;
  124. };
  125.  
  126. typedef union parg
  127. {
  128.     char *p_string;
  129.     int p_int;
  130. } PARG;
  131.  
  132. #define    NULL_PARG    ((PARG *)NULL)
  133.  
  134. struct textlist
  135. {
  136.     char *string;
  137.     char *endstring;
  138. };
  139.  
  140. #define    EOI        (-1)
  141.  
  142. #define    READ_INTR    (-2)
  143.  
  144. /* How quiet should we be? */
  145. #define    NOT_QUIET    0    /* Ring bell at eof and for errors */
  146. #define    LITTLE_QUIET    1    /* Ring bell only for errors */
  147. #define    VERY_QUIET    2    /* Never ring bell */
  148.  
  149. /* How should we prompt? */
  150. #define    PR_SHORT    0    /* Prompt with colon */
  151. #define    PR_MEDIUM    1    /* Prompt with message */
  152. #define    PR_LONG        2    /* Prompt with longer message */
  153.  
  154. /* How should we handle backspaces? */
  155. #define    BS_SPECIAL    0    /* Do special things for underlining and bold */
  156. #define    BS_NORMAL    1    /* \b treated as normal char; actually output */
  157. #define    BS_CONTROL    2    /* \b treated as control char; prints as ^H */
  158.  
  159. /* How should we search? */
  160. #define    SRCH_FORW    0    /* Search forward from current position */
  161. #define    SRCH_BACK    1    /* Search backward from current position */
  162. #define    SRCH_NOMATCH    0100    /* Search for non-matching lines */
  163. #define    SRCH_PAST_EOF    0200    /* Search past end-of-file, into next file */
  164. #define    SRCH_FIRST_FILE    0400    /* Search starting at the first file */
  165.  
  166. #define    SRCH_DIR(t)    ((t) & 01)
  167. #define    SRCH_REVERSE(t)    ((t) ^ 01)
  168.  
  169. /* */
  170. #define    NO_MCA        0
  171. #define    MCA_DONE    1
  172. #define    MCA_MORE    2
  173.  
  174. #define    CC_OK        0    /* Char was accepted & processed */
  175. #define    CC_QUIT        1    /* Char was a request to abort current cmd */
  176. #define    CC_ERROR    2    /* Char could not be accepted due to error */
  177. #define    CC_PASS        3    /* Char was rejected (internal) */
  178.  
  179. /* Special chars used to tell put_line() to do something special */
  180. #define    AT_NORMAL    (0)
  181. #define    AT_UNDERLINE    (1)
  182. #define    AT_BOLD        (2)
  183. #define    AT_BLINK    (3)
  184. #define    AT_INVIS    (4)
  185. #define    AT_STANDOUT    (5)
  186.  
  187. #define    CONTROL(c)    ((c)&037)
  188. #define    ESC        CONTROL('[')
  189.  
  190. #define    SIGNAL(sig,func)    signal(sig,func)
  191.  
  192. #define    S_INTERRUPT    01
  193. #define    S_STOP        02
  194. #define S_WINCH        04
  195. #define    ABORT_SIGS()    (sigs & (S_INTERRUPT|S_STOP))
  196.  
  197. #define    ch_zero()    ((POSITION)0)
  198.  
  199. #include "funcs.h"
  200.